import sceneutil from "../utils/sceneutil";
import gamedata from "../utils/gamedata";
import wxutils from "../utils/wxutils";
import home from "../pages/home";


// 界面适配脚本   挂载到界面main 的box上 使main  大小为当前界面大小
export default class homescript extends Laya.Script {
    public HeadComp: Laya.Sprite;//头像组件
    public MiliComp: Laya.Sprite;//米粒儿数字组件 
    /** @prop {name:head,tips:"头像",type:Prefab}*/
    head: Laya.Prefab;
    /** @prop {name:paopao,tips:"泡泡",type:Prefab}*/
    paopao: Laya.Prefab;
    /** @prop {name:milinumber,tips:"米粒数字",type:Prefab}*/
    milinumber: Laya.Prefab;
    constructor() {
        super();
    }
    onEnable() {
        this.initMainBox();
        this.initHeadImg();
    }

    //初始化头像组件    
    initHeadImg() {
        this.HeadComp = Laya.Pool.getItemByCreateFun("head", this.head.create, this.head);
        (this.HeadComp.getChildByName("img") as Laya.Image).skin = gamedata.Instance.userInfo.avatarUrl;
        let name = gamedata.Instance.userInfo.nickName;
        (this.HeadComp.getChildByName("name") as Laya.Text).text = name.slice(0, 5);
        this.HeadComp.x = 50;
        this.HeadComp.y = 20;
        home.Instance.main.addChild(this.HeadComp);


        this.MiliComp = Laya.Pool.getItemByCreateFun("milinumber", this.milinumber.create, this.milinumber);
        this.MiliComp.x = this.HeadComp.x + this.HeadComp.width + 60;
        this.MiliComp.y = 20;
        home.Instance.main.addChild(this.MiliComp);
    }



    initMainBox() {
        // //@ts-ignore
        // this.owner.height = sceneutil.Instance.realHeigt;
        // //@ts-ignore
        // this.owner.width = sceneutil.Instance.shejibili.width;
        // //@ts-ignore
        // this.owner.anchorY = 0.5;
        // //@ts-ignore
        // this.owner.anchorX = 0.5;
        // //@ts-ignore
        // this.owner.x = sceneutil.Instance.shejibili.width / 2;
        // //@ts-ignore
        // this.owner.y = sceneutil.Instance.realHeigt / 2;
        // //@ts-ignore
        // // this.owner.bgColor = "#ffffff"

        for (let i = 0; i < 2; i++) {
            let pp = Laya.Pool.getItemByCreateFun("paopao", this.paopao.create, this.paopao);
            home.Instance.zz.addChild(pp)
            pp.x = Math.random() * home.Instance.zz.width / 2;
            pp.y = Math.random() * home.Instance.zz.height / 4;

        }
    }


}